﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DuLieu;
using ThongTin;
using ThaoTac;
using System.Data.SqlClient;
namespace GiaoDien

{
    public partial class frmDanhSachSinhVien : Form
    {
        SinhVien_DL SV = new SinhVien_DL();
        public frmDanhSachSinhVien()
        {
            InitializeComponent();
            tblDanhSachSinhVien_SV.DataSource = SV.DanhSachSinhVien();
        }
        
        private void btnThem_Click(object sender, EventArgs e)
        {
            //ThemSinhVien();
            frmThongTinSinhVien tt = new frmThongTinSinhVien();
            tt.addNew += new EventHandler(add);
            tt.ShowDialog();
        }
        public void add(Object sender, EventArgs e)
        {
            frmThongTinSinhVien tt = (frmThongTinSinhVien)sender;
            DataTable dt = (DataTable)tblDanhSachSinhVien_SV.DataSource;
            dt.Rows.Add(tt.MaSinhVien,tt.TenSinhVien,tt.NgaySinh,tt.GioiTinh,tt.Lop,tt.DiaChiThuongThu,tt.NoiO,tt.ChinhSachUuTien);
            tblDanhSachSinhVien_SV.DataSource = dt;

            SqlConnection cnn = new SqlConnection();
            SqlCommand cmd = new SqlCommand("ThemSinhVien", cnn);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            SqlCommandBuilder cmb = new SqlCommandBuilder(da);

            da.UpdateCommand = cmb.GetUpdateCommand();
           
        }

    }
}